from rest_framework.serializers import Serializer,ModelSerializer
from .models import *
from  rest_framework import serializers

"""class TestRoleSer(ModelSerializer):
    class Meta:
        model = TestRole
        fields=('id','name')
    def validated_data(self, attrs):
        pass"""

class ResourceSer(ModelSerializer):
    # name = serializers.CharField(max_length=30,required=True)
    # # pid = serializers.IntegerField(required=False)
    # #
    # def validated_name(self, data):
    #     print('data=',data)
    #     ret = Resource.objects.filter(name=data).first()
    #     if ret:
    #         raise serializers.ValidationError('资源名称重复')
    #     else:
    #         return data
    class Meta:
        model = Resource
        fields = '__all__'

class RolesSer(ModelSerializer):
    # name = serializers.CharField(max_length=30,required=True)
    # pid = serializers.IntegerField(required=False)
    #
    # def validated_name(self, data):
    #     print('data=',data)
    #     ret = Roles.objects.filter(name=data).first()
    #     if ret:
    #         raise serializers.ValidationError('资源名称重复')
    #     else:
    #         return data
    class Meta:
        model = Roles
        fields = '__all__'

class AdminUserSer(ModelSerializer):
    # name = serializers.CharField(max_length=30,required=True)
    # pid = serializers.IntegerField(required=False)
    #
    # def validated_name(self, data):
    #     print('data=',data)
    #     ret = AdminUser.objects.filter(name=data).first()
    #     if ret:
    #         raise serializers.ValidationError('资源名称重复')
    #     else:
    #         return data
    class Meta:
        model = AdminUser
        fields = '__all__'